#include "appconfig_reader.h"
#include "app_common.h"
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <iostream>

using namespace boost;

static const char *kAppConfigRoot = "server";
static const char *kServerPort = "ServerPort";
static const char *kHeartbeatInterval = "HeartbeatInterval";

// load app configure
ServerConfig_t loadAppConfig(const std::string &filepath)
{
	property_tree::ptree pt;
	property_tree::ini_parser::read_ini(filepath, pt);
	property_tree::ptree client;
	client = pt.get_child(kAppConfigRoot);

	ServerConfig_t cfg;
	auto d = client.get_optional<int>(kServerPort);
	if (d)
		cfg.serverPort = *d;
	auto a = client.get_optional<int>(kHeartbeatInterval);
	if (a)
		cfg.heartbeatInterval = *a;

	return cfg;
}
